import { Body, Controller, Post } from '@nestjs/common'
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'

import { AuthService } from './auth.service'
import { LoginDto } from './dtos/auth.dto'
import {
  ErrorDto,
  LoginResponseDto,
  RegisterResponseDto
} from './dtos/Response.dto'

@ApiTags('登录相关')
@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @ApiOperation({ summary: '登录' })
  @ApiResponse({ status: 200, type: LoginResponseDto })
  @ApiResponse({ status: 400, type: ErrorDto })
  @Post('/login')
  // @UseGuards(AuthGuard('local'))
  async login(@Body() body: LoginDto) {
    return await this.authService.login(body)
  }

  @ApiOperation({ summary: '注册' })
  @ApiResponse({ status: 200, type: RegisterResponseDto })
  @ApiResponse({ status: 400, type: ErrorDto })
  @Post('/register')
  async register(@Body() body: LoginDto) {
    return await this.authService.register(body)
  }
}
